#!/bin/sh
#
SERVICE_NAME="datax-admin"
JAR_NAME="datax-admin*.jar"
GcLogPath="${GC_PATH-data}/logs/${SERVICE_NAME}"

PID=$SERVICE_NAME\.pid
JAVA_OPTS=" -Duser.timezone=Asia/Shanghai -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8"
JAVA_OPTS="${JAVA_OPTS} -verbose:gc -Xloggc:${GcLogPath}/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:ErrorFile=${GcLogPath}/hs_err_pid_%p.log"
JAVA_MEM_OPTS=" -XX:+UseG1GC -Xms${JAVA_XMX-512m} -Xmx${JAVA_XMX-512m} -Xmn${JAVA_XMN-512m} -XX:+AlwaysPreTouch -XX:-UseBiasedLocking -XX:G1HeapRegionSize=16m"
JAVA_OPTS="$JAVA_OPTS $JAVA_MEM_OPTS"
SPRING_OPTS=" --spring.profiles.active=${ACTIVE_PROFILE-prod}"

#service dir
SERVICE_DIR=`pwd`

function echoPlus(){
  # 增强显示
  # @param color  (31|91 红  32|92绿  33|93黄 34|94蓝 35|95紫 36|96天蓝)
  # @param content
  local colorCode=$1
  local content=$2

  echo -e "\e[${colorCode}m${content}\e[0m"
}

echoPlus 33 "[check] 即将启动Springboot......"
# 判断目录是否存在
if [ ! -d config ] ;
then
  mkdir -p config
fi

if [ ! -d "${GcLogPath}" ] ;
then
  mkdir -p "${GcLogPath}"
fi

# 项目文件
if [ "`ls -A config`" = "" ]; then
  cp -r -f backup/*.yml config/
fi


echoPlus 33 "java $JAVA_OPTS -jar $JAR_NAME $SPRING_OPTS"

java $JAVA_OPTS -jar $JAR_NAME $SPRING_OPTS >/dev/null 2>&1
